package com.hadoop.mr.amiudake.max;

import java.io.IOException;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

public class MaxReducer extends Reducer<Text, Text, Text, Text>{

	@Override
	protected void reduce(Text key, Iterable<Text> value, org.apache.hadoop.mapreduce.Reducer<Text, Text, Text, Text>.Context context)
			throws IOException, InterruptedException {
		try {
			Long maxid = 0L;
			String maxId = "";
			for (Text v : value) {
				String varr [] = v.toString().split("-");
				long brithday = Long.valueOf(varr[0]) ;
				if(brithday > maxid){
					maxid = brithday;
					maxId = varr[1];
				}
			}
			context.write(new Text(key), new Text(maxId));
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}
}
